﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WCFVeterinaria;

public partial class Login : System.Web.UI.Page
{
    ServiceVeterinaria service=new ServiceVeterinaria();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LoginButton_Click(object sender, EventArgs e)
    {
        string idUser = string.Empty;
        string password = string.Empty;
        string passEnc = string.Empty;
        if(string.IsNullOrEmpty(UserTextBox.Text) || string.IsNullOrEmpty(PasswordTextBox.Text))
        {
            string message = "alert('Campo vacío por favor escribir su usuario o constraseña')";
            ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);
        }

        else
        {
            idUser = UserTextBox.Text;
            password = PasswordTextBox.Text;
            passEnc = Utils.Encriptar(password);
        }

        if(service.consultarUsuario(idUser, passEnc)!=null)
        {
            Session["username"] = idUser;
            Response.Redirect("/Inicio.aspx");
        }
        else 
        {
            string message = "alert('El usuario o contraseña son incorrectos, intente nuevamente')";
            ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);
            UserTextBox.Text = string.Empty;
        }
    }
    protected void RegistreseLink_Click(object sender, EventArgs e)
    {
        Response.Redirect("/Usuarios.aspx");
    }
}